import 'package:flutter/material.dart';
import 'package:flutterdemo/common/event_bus.dart';
import 'package:flutterdemo/model/providermodel/userinfobasic.dart';
import 'package:flutterdemo/navigator/page_jump_animations.dart';
import 'package:flutterdemo/pages/tab3/compontss.dart';
// import 'package:flutterdemo/pages/tab1/statefulllesswidget.dart';
// import 'package:flutterdemo/pages/tab3/bloc/bloc_demo.dart';
import 'package:flutterdemo/pages/tab3/eventbusdemo.dart';
import 'package:flutterdemo/pages/tab3/localstorage.dart';
// import 'package:flutterdemo/pages/tab3/rxdart/rxdartdemo.dart';
// import 'package:flutterdemo/pages/tab3/stream/streamdemo.dart';
// import 'package:flutterdemo/pages/tab3/stream/streamdemo1.dart';
import 'package:provider/provider.dart';

class Tab3 extends StatefulWidget {
  Tab3({Key key}) : super(key: key);

  _Tab3State createState() => _Tab3State();
}

class _Tab3State extends State<Tab3> with AutomaticKeepAliveClientMixin {
  var myeventbus;
  String strevent = "";
  @override
  void initState() {
    super.initState();
    myeventbus = eventBus.on<HandleTestEventBus>().listen((data) {
      setState(() {
        strevent += data.str;
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    myeventbus.cancel();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    UserInfo provider = Provider.of<UserInfo>(context);
    int counter = provider.counter;
    final add = provider.add;
    final reduce = provider.reduce;
    return Scaffold(
      appBar: AppBar(
        title: Text('状态管理及stream'),
      ),
      body: Container(
        child: ListView(
          children: <Widget>[
            Row(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.all(10.0),
                  color: Colors.grey,
                  child: Text('$counter'),
                ),
                Container(
                  child: ButtonBar(
                    alignment: MainAxisAlignment.start,
                    children: <Widget>[
                      GestureDetector(
                        child: Text("同步"),
                        onTap: provider.add,
                      ),
                      FlatButton(
                        child: Text('add'),
                        onPressed: add,
                      ),
                      FlatButton(
                        child: Text('reduce'),
                        onPressed: reduce,
                      ),
                    ],
                  ),
                ),
              ],
            ),
            ListTile(
              title: Text('组件通信'),
              onTap: () {
                Navigator.of(context).push(
                  CustomeRouter(
                    ComponentCorrespondence(),
                  ),
                );
              },
            ),
            ListTile(
              title: Text('eventbus通信 - $strevent'),
              onTap: () {
                Navigator.of(context).push(
                  CustomeRouter(
                    EventBusDemo(),
                  ),
                );
              },
            ),
            ListTile(
              title: Text('本地存储'),
              onTap: () {
                Navigator.of(context).push(
                  CustomeRouter(
                    LocaStroge(),
                  ),
                );
              },
            ),
            // ListTile(
            //   title: Text('Stream'),
            //   onTap: () {
            //     Navigator.of(context).push(
            //       CustomeRouter(
            //         StreamDemo(),
            //       ),
            //     );
            //   },
            // ),
            // ListTile(
            //   title: Text('Stream1'),
            //   onTap: () {
            //     Navigator.of(context).push(
            //       CustomeRouter(
            //         StreamBuilderDemo(),
            //       ),
            //     );
            //   },
            // ),
            // ListTile(
            //   title: Text('Rxdart'),
            //   onTap: () {
            //     Navigator.of(context).push(
            //       CustomeRouter(
            //         RxDartDemo(),
            //       ),
            //     );
            //   },
            // ),
            // ListTile(
            //   title: Text('BloC'),
            //   onTap: () {
            //     Navigator.of(context).push(
            //       CustomeRouter(
            //         BlocDemo(),
            //       ),
            //     );
            //   },
            // ),
            // ListTile(
            //   title: Text('StatefulWidgetAndStatelessWidget'),
            //   onTap: () async {
            //     // 实现1
            //     Navigator.of(context)
            //         .push(
            //       CustomeRouter(
            //         StatefulWidgetAndStatelessWidget(),
            //       ),
            //     )
            //         .then(
            //       (data) {
            //         print('$data .......................');
            //       },
            //     );
            //     // 实现2
            //     // Navigator.push(
            //     //   context,
            //     //   new MaterialPageRoute(
            //     //     builder: (BuildContext context) =>
            //     //         StatefulWidgetAndStatelessWidget(),
            //     //   ),
            //     // ).then(
            //     //   (data) {
            //     //     print('$data .......................');
            //     //   },
            //     // );
            //     // 实现3
            //     // var data = await Navigator.of(context)
            //     //     .pushNamed('/statefulWidgetAndStatelessWidget');
            //     // print('$data .......................');
            //   },
            // ),
          ],
        ),
      ),
    );
  }

  bool get wantKeepAlive => true;
}
